import re
import time
#
# # 示例HTML
# html = "<p>这是一个示例 <a href='https://example.com'>链接</a></p>"
# file = f'../report.html'
#
# with open(file,'r',encoding='utf-8') as f :
#     res = f.read()
#     # 获取 用例总数，和 总持续时长
#     htmls = re.compile(r'<p class="run-count">(.*?)</p>')
#     sss = htmls.findall(res)
#     # 通过用例数
#     Passed = re.compile(r'<span class="passed">(.*?) Passed,</span>')
#     Passed1 = Passed.findall(res)
#     # 失败用例数
#     Faild = re.compile(r'<span class="failed">(.*?) Failed,</span>')
#     Faild1 = Faild.findall(res)
#     # 跳过用例数
#     Skipped = re.compile(r'<span class="skipped">(.*?) Skipped,</span>')
#     Skipped1 = Skipped.findall(res)
#     # 预期失败用例数
#     Expected = re.compile(r'<span class="xfailed">(.*?) Expected failures,</span>')
#     Expected1 = Expected.findall(res)
#     # 错误
#     Errors = re.compile(r'<span class="error">(.*?) Errors,</span>')
#     Errors1 = Errors.findall(res)
#     # 测试用例重跑
#     Reruns = re.compile(r'<span class="rerun">(.*?) Reruns</span>')
#     Reruns1 = Reruns.findall(res)
#
#     print('项目名称：MES小程序')
#     print("用例运行总数：",str(sss[0]).split(' ')[0])
#     print("通过用例数：", Passed1[0])
#     print("失败用例数：", Faild1[0])
#     print("跳过用例数：", Skipped1[0])
#     print("预期失败用例数：", Expected1[0])
#     print("错误：", Errors1[0])
#     print("测试用例重跑：", Reruns1[0])
#
#     print("总持续时长:",str(sss[0]).split(' ')[-1])
file = f'../report.html'
# 测试报告内容
with open(file, 'r', encoding='utf-8') as f:
    res = f.read()
    # 获取 用例总数，和 总持续时长
    htmls = re.compile(r'<p class="run-count">(.*?) tests took')
    caseSum = htmls.findall(res)
    # 运行时长
    runTimes = re.compile(r'<p class="run-count">34 tests took (.*?).</p>')
    runTime = runTimes.findall(res)
    # 通过用例数
    Passed = re.compile(r'<span class="passed">(.*?) Passed,</span>')
    Passed1 = Passed.findall(res)
    # 失败用例数
    Faild = re.compile(r'<span class="failed">(.*?) Failed,</span>')
    Faild1 = Faild.findall(res)
    # 跳过用例数
    Skipped = re.compile(r'<span class="skipped">(.*?) Skipped,</span>')
    Skipped1 = Skipped.findall(res)
    # 预期失败用例数
    Expected = re.compile(r'<span class="xfailed">(.*?) Expected failures,</span>')
    Expected1 = Expected.findall(res)
    # 错误
    Errors = re.compile(r'<span class="error">(.*?) Errors,</span>')
    Errors1 = Errors.findall(res)
    # 测试用例重跑
    Reruns = re.compile(r'<span class="rerun">(.*?) Reruns</span>')
    Reruns1 = Reruns.findall(res)
    currenttime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    print("运行时间：" + currenttime)
    print(caseSum[0])








